package com.example.administrator.uitest.request;

import android.content.Context;

import com.example.administrator.uitest.http.HttpUrl;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Maker on 2019/4/14.
 */

public class GetList_Request extends BaseRequest {
private boolean flag;//true 为用户排行 false 为游戏排行
    public GetList_Request(Context context,boolean flag) {
        super(context);
        this.flag = flag;
    }

    @Override
    protected Object getHttpResult(String result) {
        Map<String,Object> all = new HashMap<>();
        all.put("flag",flag);
        List<Map<String,String>> data = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(result);
            JSONArray da = jsonObject.getJSONArray("data");
            for (int i=0;i<da.length();i++){
                JSONObject js = da.getJSONObject(i);
                Map<String,String> map = new HashMap<>();
                map.put("userId",js.getString("userId"));
                map.put("shoot",js.getString("shoot"));
                map.put("hit",js.getString("hit"));
                if(flag){
                    map.put("time",js.getString("userName"));
                }else {
                    map.put("time",js.getString("time"));
                }
                data.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        all.put("data",data);
        return all;
    }

    @Override
    protected String setHttpURL() {
        if (flag){
           return HttpUrl.getAllUserShoot ;
        }else {
            return HttpUrl.getAllShoot;
        }

    }

    @Override
    protected String setHttpInface() {
        return "";
    }

    @Override
    protected String setHttpParams() {
        return "";
    }
}
